package com.zk.qqrobot.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class ComputeUtil {
    public static final int ADD = 1;
    public static final int REDUCE = 2;
    public static final int MULTIPLY = 3;
    public static final int DIVISION = 4;
    public static double compute(Double d1,Double d2,Integer operator){
        BigDecimal decimal = null;
        if (operator == ADD){
            decimal = new BigDecimal((d1 + d2)).setScale(2, RoundingMode.UP);
        }else if (operator == REDUCE){
            decimal = new BigDecimal((d1 - d2)).setScale(2, RoundingMode.UP);
        }else if (operator == MULTIPLY){
            decimal = new BigDecimal((d1 * d2)).setScale(2, RoundingMode.UP);
        }else if (operator == DIVISION){
            decimal = new BigDecimal((d1 / d2)).setScale(2, RoundingMode.UP);
        }
        return decimal.doubleValue();
    }
}
